package com.eshin.mbean;

import javax.management.Notification;

import org.springframework.jmx.export.notification.NotificationPublisher;
import org.springframework.jmx.export.notification.NotificationPublisherAware;

import com.eshin.user.User;

//继承接口的形式按接口暴露方法，spring-jmx中的assembler将无效
public class MyObject implements /**MyObjectMBean**/ NotificationPublisherAware{ 
	
private long id;  //private 变量不提供get方法将jmx将不能读取
private String name;  
private NotificationPublisher publisher; 
//public MyObject() {  
//    super();  
//}  
//  
//public MyObject(long id, String name) {  
//    super();  
//    this.id = id;  
//    this.name = name;  
//}  

public long getId() {  
    return id;  
}  

public void setId(long id) {  
    this.id = id;  
}  

public String getName() {  
    return name;  
}  

public void setName(String name) {  
    this.name = name;  
}  

public String show(int count) {  
    StringBuffer sb = new StringBuffer().append("id=").append(id).append(  
            ", name=").append(name); 
//    发送jmx通知，由NoticeListener监听
    Notification notification = new Notification("show", this, count,"publish:"+count+" times");
//    notification.setUserData(user);
    this.publisher.sendNotification(notification);
    return sb.toString();  
}
public String test(){
	System.out.println("i am test");
	return "test";
}

@Override
public void setNotificationPublisher(NotificationPublisher notificationPublisher) {
	this.publisher = notificationPublisher;
}

}  